/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {
    // 加载 errorHandler 中间件
    middleware: [ 'errorHandler', 'checkToken' ],
    // 只对 /api 前缀的 url 路径生效
    errorHandler: {
      match: '/api',
    },
    checkToken: {
      match: '/api',
    },
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1582794681616_3586';

  // add your middleware config here
  config.middleware = [ 'errorHandler', 'checkToken' ];

  config.security = {
    csrf: {
      enable: false,
    },
    xframe: {
      enable: false,
    },
    domainWhiteList: [ '*' ],
  };

  config.cors = {
    origin: '*',
    credentials: true,
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };

  config.jwt = {
    secret: 'CCGCGCCC',
  };

  config.md5 = {
    secret: 'Abc1230.',
  };

  const redisHost = {
    port: '6379', // Redis port
    host: '', // Redis host
    password: '',
  };

  const redis = redisHost;

  config.redis = {
    clients: {
      db0: { // instanceName. See below
        port: redis.port, // Redis port
        host: redis.host, // Redis host
        password: redis.password,
        db: 0,
      },
      db1: { // instanceName. See below
        port: redis.port, // Redis port
        host: redis.host, // Redis host
        password: redis.password,
        db: 1,
      },
      db2: { // instanceName. See below
        port: redis.port, // Redis port
        host: redis.host, // Redis host
        password: redis.password,
        db: 2,
      },
    },
  };

  config.sequelize = {
    dialect: 'mysql', // support: mysql, mariadb, postgres, mssql
    database: 'quick_egg', // 数据库名
    host: '127.0.0.1',
    port: '3306',
    username: 'root', // 账号
    password: 'Shmily8023', // 密码
    timezone: '+08:00', // 保存为本地时区,mysql保存时会自动保存为UTC格式
    dialectOptions: {
      dateStrings: true,
      typeCast(field, next) {
        if (field.type === 'DATETIME') {
          return field.string();
        }
        return next();
      },
    },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  return {
    ...config,
    ...userConfig,
  };
};
